import sys
import threading
import time
from PyQt5.QtWidgets import QMainWindow, QApplication, QTabBar, QWidget, QVBoxLayout
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread,pyqtSignal,QMutex
from UI.MainWindow import Ui_MainWindow
from UI.HistoryForm import Ui_HistoryForm
from UI.HomeForm import Ui_Form_home
from UI.BrowserForm import Browser_Ui_Dialog
from controller.console_controller import ConsoleController
from controller.home_controller import HomeController



class TabHistory(QWidget, Ui_HistoryForm):
    def __init__(self, parent=None,):
        super(TabHistory, self).__init__(parent)
        self.setupUi(self)
        self.pushButton_query.clicked.connect(self.pr_test)
    def pr_test(self):
        print("这是查询页面输出")
#
#
class BrowserMenu(QWidget, Browser_Ui_Dialog):
    def __init__(self):
        super(BrowserMenu, self).__init__()
        self.setupUi(self)


class Main(QMainWindow, Ui_MainWindow):
    def __init__(self,login_user=None):
        super(Main, self).__init__()
        self.setupUi(self)
        self.login_user = login_user
        # self.tab_history = TabHistory(self)
        self.connect_event()
        self.open0()

    def connect_event(self):
        # 隐藏所有的Tab widget页面
        self.tabBar = self.tabWidget.findChild(QTabBar)
        self.tabBar.hide()
        self.pushButton_home.clicked.connect(self.open0)
        self.pushButton_star_robot.clicked.connect(self.open1)
        self.pushButton_robot_console.clicked.connect(self.open2)
        self.pushButton_history.clicked.connect(self.open3)


    def open0(self):
        self.tabWidget.setCurrentIndex(0)
        q_layout = QVBoxLayout()
        self.home = HomeController()
        q_layout.addWidget(self.home)
        self.tab_home.setLayout(q_layout)

    def open1(self):
        self.tabWidget.setCurrentIndex(1)
        q_layout = QVBoxLayout()
        q_layout.addWidget(BrowserMenu())
        self.tab_star_robot.setLayout(q_layout)
        # self.tabWidget.setLayout(q_layout)

    def open2(self):
        # self.refresh_thread.stop()
        self.tabWidget.setCurrentIndex(2)
        q_layout = QVBoxLayout()
        tab_console = ConsoleController()
        q_layout.addWidget(tab_console)
        self.tab_robot_console.setLayout(q_layout)

    def open3(self):
        # self.refresh_thread.stop()
        self.tabWidget.setCurrentIndex(3)
        q_layout = QVBoxLayout()
        # widget = QWidget()
        tab_history = TabHistory()
        q_layout.addWidget(tab_history)
        self.tab_history.setLayout(q_layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Main()
    w.connect_event()
    # w.open0()
    # w.show()
    sys.exit(app.exec_())
